﻿using System.Collections.Generic;
using System.Reflection;
using NUnit.Framework;
using TestDoc;

namespace Specs_For_DllParser
{
    [TestFixture]
    public class WhenFormattingOutputSpecs
    {
        private Assembly _assembly;

        #region Setup and Teardown methods
        [TestFixtureSetUp]
        public void BeforeSuite()
        {
            _assembly = Assembly.GetExecutingAssembly();
        }

        [TestFixtureTearDown]
        public void AfterSuite()
        {
        }

        [SetUp]
        public void BeforeEachSpec()
        {
        }

        [TearDown]
        public void AfterEachSpec()
        {
        }
        #endregion Setup and teardown methods

        [Test]
        public void Should_List_Namespace_Type_And_Methods()
        {
            // Arrange
            var parser = new TestParser(_assembly);

            IList<MethodInfo[]> methods = parser.GetTests();
            var oneMethod = new MethodInfo[1];
            oneMethod[0] = methods[1][0];
            IList<MethodInfo[]> myMethods = new List<MethodInfo[]> { oneMethod };

            // Act
            IList<MethodInfoSmall> output = parser.FormatTestReport(myMethods);

            // Assert
            Assert.IsNotNull(output, "null output");
            Assert.IsTrue(output.Count == 3, "count wrong");
            Assert.IsTrue(output[0].TypeCode ==  MethodType.Namespace, "Namespace");
            Assert.IsTrue(output[1].TypeCode == MethodType.ClassName, "Class");
            Assert.IsTrue(output[2].TypeCode == MethodType.MethodName, "Method");
        }

        [Test]
        public void Should_Replace_Underscore_With_Spaces()
        {
            const string methodName = "Should_Replace_Underscore_With_Spaces";

            // Arrange
            var parser = new TestParser(_assembly);

            // Act
            var methods = parser.GetTests();
            var formattedMethods = parser.FormatTestReport(methods);            

            // Assert
            Assert.IsFalse(formattedMethods.Contains(new MethodInfoSmall(MethodType.MethodName, methodName)), "Not formatted");
            Assert.IsTrue(formattedMethods.Contains(new MethodInfoSmall(MethodType.MethodName, methodName.Replace('_', ' '))), "Sentence format");
        }

        [Test]
        public void ShouldReplaceCamelCaseWithSpaces()
        {
            const string methodName = "ShouldReplaceCaseWithSpaces";

            // Arrange
            var parser = new TestParser(_assembly);

            // Act
            var methods = parser.GetTests();
            var formattedMethods = parser.FormatTestReport(methods);

            // Assert
            Assert.IsFalse(formattedMethods.Contains(new MethodInfoSmall(MethodType.MethodName, methodName)), "Not formatted");
            Assert.IsTrue(formattedMethods.Contains(new MethodInfoSmall(MethodType.MethodName, "Should Replace Camel Case With Spaces")), "Sentence format");
            
        }

        [Test]
        public void ShouldFormatClassNames()
        {
            const string className = "WhenFormattingOutputSpecs";

            // Arrange
            var parser = new TestParser(_assembly);

            // Act
            var methods = parser.GetTests();
            var formattedMethods = parser.FormatTestReport(methods);

            // Assert
            Assert.IsFalse(formattedMethods.Contains(new MethodInfoSmall(MethodType.ClassName, className)), "Not formatted");
            Assert.IsTrue(formattedMethods.Contains(new MethodInfoSmall(MethodType.ClassName, "When Formatting Output Specs")), "Sentence format");
            
        }

        [Test]
        public void ShouldFormatNameSpaces()
        {
            const string nameSpace = "Specs For Dll Parser";

            // Arrange
            var parser = new TestParser(_assembly);

            // Act
            var methods = parser.GetTests();
            var formattedMethods = parser.FormatTestReport(methods);

            // Assert
            Assert.IsTrue(formattedMethods.Contains(new MethodInfoSmall(MethodType.Namespace, nameSpace)), "Sentence format");

        }

    }
}